/* Process.h
Michael Zahniser, 12/21/09

Header file for the Process class, which represents a process that is launched
via fork() and whose output is piped into the input of this process.

When the process is Stop()ed, the old input source is restored.
*/

#ifndef __MZ_PROCESS_H__
#define __MZ_PROCESS_H__

#include <string>
#include <vector>



class Process {
public:
	Process();
	~Process();
	
	void Start(const std::string &command, char **argv = NULL);
	// Kill the process.
	void Kill();
	// Wait nicely for the process to finish up.
	void Wait();
	

private:
	void Start();
	void CleanUp();
	void DoParent();
	void DoChild();
	
	
private:
	std::vector<std::string> tokens;
	char **args;
	
	int childProcess;
	int stdinCopy;
	int pipe_fd[2];
};

#endif
